import { hp } from '@/utils/util'

const SERVER_PATH = process.env.NUXT_SERVER_PATH
const SERVER_PORT = process.env.NUXT_SERVER_PORT
const BASEURL = SERVER_PATH === 'localhost' ? `http://${SERVER_PATH}:${SERVER_PORT}` : ''

export default $axios => resource => ({
  getByPage (pageNum, pageSize, params) {
    return $axios.$post(`${BASEURL}/authentication-server${resource}/query?pageNum=${pageNum}&pageSize=${pageSize}`, hp(params))
  },

  get (id) {
    return $axios.$get(`${BASEURL}/authentication-server${resource}/${id}`)
  },

  add (params) {
    return $axios.$post(`${BASEURL}/authentication-server${resource}`, hp(params))
  },

  addRRR (roleId, resourceId) {
    return $axios.$post(`${BASEURL}/authentication-server${resource}/addRRR/${roleId}/${resourceId}`)
  },

  delRRR (roleId, resourceId) {
    return $axios.$delete(`${BASEURL}/authentication-server/${resource}/delRRR/${roleId}/${resourceId}`)
  },

  addRRRs (roleId, domainId) {
    return $axios.$post(`${BASEURL}/authentication-server${resource}/addRRRs/${roleId}/${domainId}`)
  },

  delRRRs (roleId, domainId) {
    return $axios.$delete(`${BASEURL}/authentication-server${resource}/delRRRs/${roleId}/${domainId}`)
  },

  getAllPermission () {
    return $axios.$post(`${BASEURL}/authentication-server${resource}/queryAll`)
  },

  addOne (id, params) {
    return $axios.$post(`${BASEURL}/authentication-server${resource}/one/${id}`, hp(params))
  },

  delOne (id) {
    return $axios.$delete(`${BASEURL}/authentication-server${resource}/one/${id}`)
  },

  updateOne (id, params) {
    return $axios.$put(`${BASEURL}/authentication-server${resource}/one/${id}`, hp(params))
  },

  update (id, params) {
    return $axios.$put(`${BASEURL}/authentication-server${resource}/${id}`, hp(params))
  },

  del (id) {
    return $axios.$delete(`${BASEURL}/authentication-server${resource}/${id}`)
  },

  toggle (params) {
    return $axios.$post(`${BASEURL}/authentication-server${resource}/toggle`, hp(params))
  }
})
